function [ROIs] = STA_ROI(ROIs, spktimes, frametimes)
preframes = 40;
postframes = 40;

cut = max(find(spktimes<frametimes(length(frametimes)-50)));
spkframes = zeros(size(cut));

for ind = 1:cut
    spkframes(ind) = min(find(frametimes > spktimes(ind)));
end

for ind = 1:size(ROIs,2)
    for spk = 1:length(spkframes)
        ROIs(ind).segments(1:preframes+postframes+1,spk) = ROIs(ind).activity(spkframes(spk)-preframes:spkframes(spk)+postframes);
    end
end